<template>
  <div>
    <div style="height: 60px; background-color: #fff; display: flex; align-items: center; border-bottom: 1px solid #ddd">
      <div style="flex: 1">
        <div style="padding-left: 20px; display: flex; align-items: center">
         <!--<img src="@/assets/imgs/logo.png" alt="" style="width: 40px">-->
          <div style="font-weight: bold; font-size: 19px; margin-left: 5px">生活分享后台管理端</div>
        </div>
      </div>
      <div style="width:fit-content; padding-right: 10px; display: flex; align-items: center;">
        <img src="../assets/imgs/admin.jpg" alt="" style="width: 40px; height: 40px; border-radius: 50%">
        <span style="margin-left: 5px">{{ state.user.username }}</span>
        <div style="width:100px;height:40px;cursor: pointer;display: flex; align-items: center;margin-left:20px;" @click="logout">
            <el-icon><SwitchButton /></el-icon>
            <span style="margin-left:4px">退出系统</span>
         </div>
      </div>
    </div>

    <div style="display: flex">
      <div style="width: 200px; border-right: 1px solid #ddd; min-height: calc(100vh - 60px)">
        <el-menu
            router
            style="border: none"
            :default-active="$route.path"
            :default-openeds="['/home', '2', '3']"
        >
          <el-menu-item index="/home">
            <el-icon><HomeFilled /></el-icon>
            <span>系统首页</span>
          </el-menu-item>
          <el-menu-item index="/xk">
              <el-icon><Tickets /></el-icon>
              <span>信息管理</span>
          </el-menu-item>
          <el-menu-item index="/category">
            <el-icon><Operation /></el-icon>
            <span>分类管理</span>
          </el-menu-item>
          <el-menu-item index="/user">
              <el-icon><UserFilled /></el-icon>
              <span>用户信息</span>
          </el-menu-item>
<!--          <el-menu-item index="/person" v-if="user.role === 'STUDENT'">-->
<!--            <el-icon><User /></el-icon>-->
<!--            <span>个人资料</span>-->
<!--          </el-menu-item>-->
        </el-menu>
      </div>

      <div style="flex: 1; width: 0; background-color: #f8f8ff; padding: 10px">
        <router-view />
      </div>
    </div>

  </div>
</template>

<script setup>
import { useRoute } from 'vue-router'
import {ElMessage, ElMessageBox} from "element-plus";
import router from "../router";
const $route = useRoute()
const state=reactive({
  user:JSON.parse(localStorage.getItem('userInfo') || '{}')
})

const logout = () => {
  ElMessageBox.confirm(
      '您确定退出系统吗?',
      '系统提示',
      {
        confirmButtonText: '确认',
        cancelButtonText: '取消',
        type: 'warning',
        duration: 1000
      }
  )
      .then(() => {
        localStorage.removeItem('userInfo')
        localStorage.setItem('token',"")
        ElMessage({
          type: 'success',
          message: '您已退出登录',
          duration: 1000
        })
        router.push('/login')
      })
}
</script>

<style scoped>
.el-menu-item.is-active {
  background-color: #dcede9 !important;
}
.el-menu-item:hover {
  color: #11A983;
}
:deep(th)  {
  color: #333;
}
</style>
